clear
set matsize 11000
use "C:\Users\karti\Documents\Data\regressions\paper_2\data_corrected_for_regs_DDD.dta", clear



/*


save "C:\Users\karti\Documents\Data\regressions\paper_2\data_corrected_for_regs_DDD_with nssdist.dta", replace
*/
merge m:1 new_state_dist_code round using "C:\Users\karti\Documents\Data\regressions\paper_2\data_02_21_all_round_districts.dta"
keep if _m==3
drop _m

save "C:\Users\karti\Documents\Data\regressions\paper_2\data_corrected_for_regs_DDD_with nssdist.dta", replace


tab yr_qtr, gen(yr_qtr_id)

tab new_state_dist_code, gen(nssdist)
gen t2 =  time - 1
forvalues j = 1/150 {
*linear
gen nssdist_`j'=nssdist`j'*t2
}



foreach var of varlist yr_qtr_id*{
gen treat_dumm_`var' = `var'*marketing_reform
}

foreach var of varlist wheat_prod rice_prod no_agri_worker_united agri_worker cultivator cult_daily cult_days ag_days{
gen `var'_post = `var'*post_dif 
}


areg log_real_agwage treat_dumm_yr_qtr_id* marketing_reform ///
i.yr_qtr nssdist_* age hhsize hindu muslim r_others sc st c_others ///
wheat_prod rice_prod no_agri_worker_united agri_worker ///
[aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)

gen b_20 = _b[treat_dumm_yr_qtr_id20]
gen se_20 = _se[treat_dumm_yr_qtr_id20]
gen b_19 = _b[treat_dumm_yr_qtr_id19]
gen se_19 = _se[treat_dumm_yr_qtr_id19]
gen b_18 = _b[treat_dumm_yr_qtr_id18]
gen se_18 = _se[treat_dumm_yr_qtr_id18]
gen b_17 = _b[treat_dumm_yr_qtr_id17]
gen se_17 = _se[treat_dumm_yr_qtr_id17]
gen b_16 = _b[treat_dumm_yr_qtr_id16]
gen se_16 = _se[treat_dumm_yr_qtr_id16]
gen b_15 = _b[treat_dumm_yr_qtr_id15]
gen se_15 = _se[treat_dumm_yr_qtr_id15]
gen b_14 = _b[treat_dumm_yr_qtr_id14]
gen se_14 = _se[treat_dumm_yr_qtr_id14]
gen b_13 = _b[treat_dumm_yr_qtr_id13]
gen se_13 = _se[treat_dumm_yr_qtr_id13]
gen b_12 = _b[treat_dumm_yr_qtr_id12]
gen se_12 = _se[treat_dumm_yr_qtr_id12]
gen b_11 = _b[treat_dumm_yr_qtr_id11]
gen se_11 = _se[treat_dumm_yr_qtr_id11]
gen b_10 = _b[treat_dumm_yr_qtr_id10]
gen se_10 = _se[treat_dumm_yr_qtr_id10]
gen b_9 = _b[treat_dumm_yr_qtr_id9]
gen se_9 = _se[treat_dumm_yr_qtr_id9]
gen b_8 = _b[treat_dumm_yr_qtr_id8]
gen se_8 = _se[treat_dumm_yr_qtr_id8]
gen b_7 = _b[treat_dumm_yr_qtr_id7]
gen se_7 = _se[treat_dumm_yr_qtr_id7]
gen b_6 = _b[treat_dumm_yr_qtr_id6]
gen se_6 = _se[treat_dumm_yr_qtr_id6]
gen b_5 = _b[treat_dumm_yr_qtr_id5]
gen se_5 = _se[treat_dumm_yr_qtr_id5]
gen b_4 =  0
gen se_4 = 0
gen b_3 = _b[treat_dumm_yr_qtr_id3]
gen se_3 = _se[treat_dumm_yr_qtr_id3]
gen b_2 = _b[treat_dumm_yr_qtr_id2]
gen se_2 = _se[treat_dumm_yr_qtr_id2]
gen b_1 = _b[treat_dumm_yr_qtr_id1]
gen se_1 = _se[treat_dumm_yr_qtr_id1]

keep in 1 

keep b_* se_*

qui gen i=.
reshape long b_ se_, i(i) j(x) s

qui gen u = b_ + 1.96*se_
qui gen l = b_ - 1.96*se_


replace i=-4 if x=="1"
replace i=-3 if x=="2"
replace i=-2 if x=="3"
replace i=-1 if x=="4"
replace i=0 if x=="5"
replace i=1 if x=="6"
replace i=2 if x=="7"
replace i=3 if x=="8"
replace i=4 if x=="9"
replace i=5 if x=="10"
replace i=6 if x=="11"
replace i=7 if x=="12"
replace i=8 if x=="13"
replace i=9 if x=="14"
replace i=10 if x=="15"
replace i=11 if x=="16"
replace i=12 if x=="17"
replace i=13 if x=="18"
replace i=14 if x=="19"
replace i=15 if x=="20"

sort i
*drop if i<-4
*drop if i>1
*keep if i==-4| i==-3|i==-2|i==-1|i==0|i==2| i==4| i==6
tw (line u i, lpattern(shortdash) lcolor(gray)  )  ||  ///
(line l i, lpattern(shortdash) lcolor(gray)) || (connected b i, mcolor(red) lcolor(red)), xtitle("Year") yline(0, lc(maroon)) ///
 xtitle("Year-Quarter") ytitle("Ln Agricultural Wages")  title() ///
 xlabel(-5(1)16) ///
plotregion(fcolor(white)) graphregion(fcolor(white)) ///
legend( cols(2) order(3 "Estimated Coefficient" 2 "95% Confidence Interval")) ///

saving(g2n)
